import Lockr from 'lockr/lockr.js'
const user = {
    state: {
        token: '',
        refresh_token: '',
        expires_in: '',
        jti: '',
        scope: '',
        token_type: '',
        userInfo: {},
        theme: ''
    },
    mutations: {
        saveTheme(state, theme) {
            state.theme = theme
            Lockr.set('theme', state.theme)
        },
        getTheme(state) {
            state.theme = Lockr.get('theme')
        },
        SET_ACCESS_TOKEN(state, token) {
            state.token = token
            Lockr.set('token', state.token)
        },
        GET_ACCESS_TOKEN(state) {
            state.token = Lockr.get('token')
        },
        SET_REFRESH_TOKEN(state, refresh_token) {
            state.refresh_token = refresh_token
            Lockr.set('refresh_token', state.refresh_token)
        },
        GET_REFRESH_TOKEN(state) {
            state.refresh_token = Lockr.get('refresh_token')
        },
        SET_EXPIRES_IN(state, expires_in) {
            state.expires_in = expires_in
            Lockr.set('expires_in', state.expires_in)
        },
        SET_JTI(state, jti) {
            state.jti = jti
            Lockr.set('jti', state.jti)
        },
        SET_SCOPE(state, scope) {
            state.scope = scope
            Lockr.set('scope', state.scope)
        },
        SET_TOKEN_TYPE(state, token_type) {
            state.token_type = token_type
            Lockr.set('token_type', state.token_type)
        },
        saveUserInfo(state, userInfo) {
            state.userInfo = userInfo
            Lockr.set('userInfo', state.userInfo)
        },
        getUserInfo(state) {
            state.userInfo = Lockr.get('userInfo')
        }
    },
    actions: {
        saveTheme({ commit }, theme) {
            commit('saveTheme', theme)
        },
        getTheme({ commit }) {
            commit('getTheme')
        },
        SET_ACCESS_TOKEN({ commit }, token) {
            commit('SET_ACCESS_TOKEN', token)
        },
        GET_ACCESS_TOKEN({ commit }) {
            commit('GET_ACCESS_TOKEN')
        },
        SET_REFRESH_TOKEN({ commit }, refresh_token) {
            commit('SET_REFRESH_TOKEN', refresh_token)
        },
        GET_REFRESH_TOKEN({ commit }) {
            commit('GET_REFRESH_TOKEN')
        },
        SET_EXPIRES_IN({ commit }, expires_in) {
            commit('SET_EXPIRES_IN', expires_in)
        },
        SET_JTI({ commit }, jti) {
            commit('SET_JTI', jti)
        },
        SET_SCOPE({ commit }, scope) {
            commit('SET_SCOPE', scope)
        },
        SET_TOKEN_TYPE({ commit }, token_type) {
            commit('SET_TOKEN_TYPE', token_type)
        },
        saveUserInfo({ commit }, userInfo) { //权限
            commit('saveUserInfo', userInfo)
        },
        getUserInfo({ commit }) {
            commit('getUserInfo')
        }
    }
}

export default user